import java.util.Random;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;

/**
 * 生成消息
 */
public class MessageGenerator extends Thread {

  private CellularPhone phone;

  public MessageGenerator(String name, CellularPhone aPhone) {
    super(name);
    phone = aPhone;
  }


  public void run() {
    int counter = 0;
    Random randomGenerator = new Random();
    while (counter++ < 20) {
      try {
        phone.addMessage(getName() + " " + counter);
        sleep(200);
      } catch (InterruptedException ie) {
        System.err.println("消息生成器中断");
      }
    }
  }


}